<?php
/**
 * 相关内容操作
 * User: soshow
 * Date: 17/4/17
 * Time: 下午5:30
 */
class serviceControl extends SystemControl{

    private $links = array(
        array('url'=>'act=service&op=index','lang'=>'service_index'),
        //array('url'=>'act=service&op=service_add','lang'=>'nc_new')
    );


    public function __construct(){
        parent::__construct();
        Language::read('service');
    }

    //相关内容
    public function indexOp(){
        $model = Model('service');
        if (chksubmit()){
            if (!empty($_POST['del_id'])){
                if (is_array($_POST['del_id'])){
                    foreach ($_POST['del_id'] as $k => $v){
                        $model->delService(array('service_id'=>intval($v)));
                    }
                }
                $this->log(L('nc_delete,service_index').'[service_id:'.intval($_POST['del_id']).']',1);
                showMessage(L('nc_common_del_succ'));
            }else {
                $this->log(L('nc_delete,service_index').'[service_id:'.intval($_POST['del_id']).']',0);
                showMessage(L('nc_common_del_fail'));
            }
        }

        $list = $model->getServiceList(array(),'*',15,'service_sort desc, service_id desc');
        Tpl::output('list',$list);
        Tpl::output('top_link', $this->sublink($this->links, 'index'));
        Tpl::output('page',$model->showpage());
        Tpl::showpage('service.index');
    }

    //新增
    function service_addOp(){
        $model = Model('service');
        if(chksubmit()){
            $param['service_title']         = $_POST['service_title'];
            $param['service_introduction']  = $_POST['service_introduction'];
            $param['service_sort']          = $_POST['service_sort'];
            $param['service_content']       = $_POST['content'];
            $param['addtime']               = time();

            $rs = $model->addService($param);
            if ($rs){
                $this->log(L('nc_add,service_index').'[service_title:'.intval($_POST['service_title']).']',1);
                showMessage(L('nc_common_save_succ'),'index.php?act=service&op=index');
            }else {
                $this->log(L('nc_add,service_index').'[service_title:'.intval($_POST['service_title']).']',0);
                showMessage(L('nc_common_save_fail'));
            }
        }
        Tpl::output('top_link', $this->sublink($this->links, 'brand_add'));
        Tpl::showpage('service.add');
    }

    //编辑
    public function service_editOp(){
        $model = Model('service');
        $service_id = $_GET['service_id'];
        if(chksubmit()){
            $service_id = $_POST['service_id'];
            $param['service_title']         = $_POST['service_title'];
            $param['service_introduction']  = $_POST['service_introduction'];
            $param['service_sort']          = $_POST['service_sort'];
            $param['service_content']       = $_POST['content'];
            $result = $model->updateService(array('service_id'=>$service_id),$param);
            if($result){

                $this->log(L('nc_edit,service_index').'[service_id:'.intval($_POST['service_id']).']',1);
                showMessage(L('nc_common_op_succ'),'index.php?act=service&op=index');
            }else {
                $this->log(L('nc_edit,service_index').'[service_id:'.intval($_POST['service_id']).']',0);
                showMessage(L('nc_common_op_fail'));
            }
        }
        $serviceInfo = $model->getServiceInfo(array('service_id'=>$service_id));
        Tpl::output('serviceInfo',$serviceInfo);
        Tpl::output('top_link', $this->sublink($this->links, 'service_edit'));
        Tpl::showpage('service.edit');
    }

    // 删除
    function service_delOp(){
        if (!empty($_GET['service_id'])){
            $model = Model('service');
            $model->delService(array('service_id'=>intval($_GET['service_id'])));

            $this->log(L('nc_delete,service_index').'[service_id:'.intval($_GET['service_id']).']',1);
            showMessage(L('nc_common_del_succ'));
        }else {
            $this->log(L('nc_delete,service_index').'[service_id:'.intval($_GET['service_id']).']',0);
            showMessage(L('nc_common_del_fail'));
        }
    }


}